import java.util.Scanner;

public class Main {
    public  static  boolean isDaffodil(int n) {
        int dig=String.valueOf(n).length();
        int sum=0;
        int temp=n;
        while (temp>0){
            int s=temp%10;
            sum+=Math.pow(s,dig);
            temp=temp/10;
        }
        return sum==n;
    }
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    for (int i = 0; i <= n; i++) {
        if(isDaffodil(i))System.out.print(i+" ");
        }
    }


    public static void main5(String[] args) {
        int s=1;
        double a=0;
        for (int i = 1; i <= 100; i++) {

            a=a+(1.0/i)*s;
            s=-s;
        }
        System.out.println(a);
    }
    
    
    public static int ret4(int a, int b) {
        while (b != 0) {
            int temp=b;
            b=a%b;
            a=temp;
        }
        return a;
    }
    public static void main4(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
    int c=ret4(a,b);
        System.out.println(c);
    }


    public static int count3(int n) {
        int ret = 0;
        while (n > 0) {
            if(n%10==9){
                ret++;
            }
            n/=10;
        }
        return ret;
    }
    public static void main3(String[] args) {
        int sum =0;
        for (int i = 1; i <=100 ; i++) {
            sum+=count3(i);
        }
        System.out.println(sum);
    }

    public static boolean isleapYear2(int year) {
            if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                return true;
        }
        return false;
    }

    public static void main2(String[] args) {
        for (int i = 1000; i <=2000 ; i++) {
            if (isleapYear2(i)) {
                System.out.print(i+" ");
            }
        }
    }
    public static boolean isPrime1(int n) {
        if(n<2)return false;
        for (int i = 2; i <=Math.sqrt(n) ; i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }
    public static void main1(String[] args) {
        for (int i = 1; i <= 100; i++) {
            if(isPrime1(i)) {
                System.out.print(i+" ");
            }
        }
    }
}